#ifndef _FLV_H
#define _FLV_H


#define FLV_SIZE_HEADER         9
#define FLV_SIZE_PREVIOUSTAG    4
#define FLV_SIZE_TAGHEADER		11
#define FLV_TAG_SCRIPTDATA		18

#define FLV_UI8(x) (unsigned int)(*(x))
#define FLV_UI32(x) (unsigned int)(((*(x)) << 24) + ((*(x + 1)) << 16) + ((*(x + 2)) << 8) + (*(x + 3)))
#define FLV_UI24(x) (unsigned int)(((*(x)) << 16) + ((*(x + 1)) << 8) + (*(x + 2)))
#define FLV_TIMESTAMP(x) (int)(((*(x + 3)) << 24) + ((*(x)) << 16) + ((*(x + 1)) << 8) + (*(x + 2)))


struct FLVTag_t{
	off_t offset;			// Offset from the beginning of the file

	// FLV spec v10
	unsigned int tagtype;
	size_t datasize;		// Size of the data contained in this tag
	int timestamp;
	short keyframe;			// Is this tag a keyframe?

	size_t tagsize;		// Size of the whole tag including header and data
};

int readFLVTag(struct FLVTag_t *flvtag, off_t offset, int fd) ;
int validateFLV(int fd, struct stat *st, int offset);

#endif
